home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3bpluginfactory.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  2.4 KB  |  99 lines

  1. /*
  2.  *
  3.  * $Id: k3bpluginfactory.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16.  
  17. #ifndef _K3B_PLUGIN_FACTORY_H_
  18. #define _K3B_PLUGIN_FACTORY_H_
  19.  
  20. #include <klibloader.h>
  21. #include <kinstance.h>
  22. #include <kglobal.h>
  23. #include <klocale.h>
  24.  
  25. /**
  26.  * Template based on KGenericFactory. This is just here to avoid using the QStringList args parameter
  27.  * in every plugin's constructor.
  28.  *
  29.  * Use this as follows:
  30.  * K_EXPORT_COMPONENT_FACTORY( libk3bartsaudioserver, K3bPluginFactory<K3bArtsAudioServer>( "k3bartsaudioserver" ) )
  31.  *
  32.  * See KGenericFactory for more information.
  33.  */
  34. template <class T>
  35. class K3bPluginFactory : public KLibFactory
  36. {
  37.  public:
  38.   K3bPluginFactory( const char* instanceName )
  39.     : m_instanceName(instanceName) {
  40.     s_self = this;
  41.     m_catalogueInitialized = false;
  42.   }
  43.  
  44.   ~K3bPluginFactory() {
  45.     if ( s_instance )
  46.       KGlobal::locale()->removeCatalogue( s_instance->instanceName() );
  47.     delete s_instance;
  48.     s_instance = 0;
  49.     s_self = 0;
  50.   }
  51.  
  52.   static KInstance* instance();
  53.  
  54.  protected:
  55.   virtual void setupTranslations( void ) {
  56.     if( instance() )
  57.       KGlobal::locale()->insertCatalogue( instance()->instanceName() );
  58.   }
  59.  
  60.   void initializeMessageCatalogue() {
  61.     if( !m_catalogueInitialized ) {
  62.       m_catalogueInitialized = true;
  63.       setupTranslations();
  64.     }
  65.   }
  66.  
  67.   virtual QObject* createObject( QObject *parent, const char *name,
  68.                  const char*, const QStringList& ) {
  69.     initializeMessageCatalogue();
  70.     return new T( parent, name );
  71.   }
  72.  
  73.  private:
  74.   QCString m_instanceName;
  75.   bool m_catalogueInitialized;
  76.  
  77.   static KInstance* s_instance;
  78.   static K3bPluginFactory<T> *s_self;
  79. };
  80.  
  81.  
  82. template <class T>
  83. KInstance* K3bPluginFactory<T>::s_instance = 0;
  84.  
  85.  
  86. template <class T>
  87. K3bPluginFactory<T>* K3bPluginFactory<T>::s_self = 0;
  88.  
  89.  
  90. template <class T>
  91. KInstance* K3bPluginFactory<T>::instance()
  92. {
  93.   if( !s_instance && s_self )
  94.     s_instance = new KInstance( s_self->m_instanceName );
  95.   return s_instance;
  96. }
  97.  
  98. #endif
  99.